package com.szh.zx.duoxiancheng.chapter1;

public class TestBuyTicket {
	public static void main(String[] args) {
		BuyTicket buyTicket =new BuyTicket();
		new Thread(buyTicket,"ddd").start();
		new Thread(buyTicket," 1").start();
		new Thread(buyTicket," 2").start();
	}
}
class BuyTicket implements Runnable{
	private int tickNum = 100;
	boolean flag = true;
	@Override
	public void run() {
		while (flag){
			buy();
		}
	}
	void buy(){
		if (tickNum<= 0){
			flag = false;
			return;
		}
		System.out.println(Thread.currentThread().getName()+"拿到了："+tickNum--);
	}
}
